GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

demo.js ➔ load_sbAdmin2Js   F
last analyzed

Complexity

Conditions 21

Size

Total Lines 51
Code Lines 35

Duplication

Lines 51
Ratio 100 %

Importance

Changes 0
Metric Value
cc 21
eloc 35
dl 51
loc 51
rs 0
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

Complexity

Complex classes like demo.js ➔ load_sbAdmin2Js often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1 View Code Duplication
app.run(function($rootScope, $transitions, $timeout, $q, $trace){
2
    // http://prismjs.com/extending.html#highlight-all
3
    // Rerun Prism syntax highlighting on the current page
4
    // http://prismjs.com/plugins/normalize-whitespace/
5
    Prism.plugins.NormalizeWhitespace.setDefaults({
6
        // 'remove-trailing': true,
7
        // 'remove-indent': true,
8
        'left-trim': true,
9
        // 'right-trim': true,
10
        /*'break-lines': 80,
11
        'indent': 2,
12
        'remove-initial-line-feed': false,
13
        'tabs-to-spaces': 4,
14
        'spaces-to-tabs': 4*/
15
    });
16
17
    // multi-language setting
18
    // $rootScope.langInstance = new Lang();
19
    // $rootScope.langInstance.init({
20
    //     defaultLang: 'en',
21
    //     currentLang: 'en',
22
    // });
23
24
    // $rootScope.switchLanguage = function(langCode_iso639){
25
    //     $rootScope.langInstance.change(langCode_iso639)
26
    // }
27
    
28
    // initial the menu after the ng-include finished
29
    $rootScope.$on("$includeContentLoaded", function(event, templateName){
30
    });
31
    // https://docs.angularjs.org/api/ng/service/$location#events
32
    $rootScope.$on("$locationChangeStart", function(event, nUrl, oUrl, newState, oldState){
33
    });
34
    $rootScope.$on("$locationChangeSuccess", function(event, nUrl, oUrl, newState, oldState){
35
    });
36
  
37
    // https://docs.angularjs.org/api/ngRoute/directive/ngView#event-$viewContentLoaded
38
    $rootScope.$on("$viewContentLoaded", function(targetScope){
39
        Prism.highlightAll();
40
        Prism.fileHighlight();
41
42
        $('.nav-tabs a').click(function (e) {
43
            e.preventDefault()
44
            $(this).tab('show')
45
        })
46
    
47
        // if add <base target="_self"> in index.html, no effect.
48
        $('.nav-tabs a').attr('target','_self');
49
    });
50
51
    // https://ui-router.github.io/guide/transitions#lifecycle-events
52
    $transitions.onFinish({}, function(transition) {
53
        // console.dir("onFinish Transition from " + transition.from().name +
54
        //   " to " + transition.to().name)
55
    });
56
57
    $transitions.onSuccess({}, function(transition) {
58
        load_sbAdmin2Js(transition);
59
        var pageName = transition.to().name;
0 ignored issues
show
Unused Code introduced by
The variable pageName seems to be never used. Consider removing it.
Loading history...
60
61
        // multi-language setting
62
        // $rootScope.langInstance.dynamic('en', '../demo/lang/demoHome.en.json');
63
        // $rootScope.langInstance.dynamic('zh-hans', '../demo/lang/demoHome.zh-hans.json');
64
        // $rootScope.langInstance.dynamic('zh-hant', '../demo/lang/demoHome.zh-hant.json');
65
        
66
        // $rootScope.langInstance.dynamic('en', '../demo/lang/'+pageName+'.en.json');
67
        // $rootScope.langInstance.dynamic('zh-hans', '../demo/lang/'+pageName+'.zh-hans.json');
68
        // $rootScope.langInstance.dynamic('zh-hant', '../demo/lang/'+pageName+'.zh-hant.json');
69
        // $rootScope.langInstance.loadPack($rootScope.langInstance.currentLang, function(err, lang, path){
70
        //     if (!err) {
71
        //     } else {
72
        //         console.log("load language pack failure")
73
        //         console.log(err)
74
        //         console.log(lang)
75
        //         console.log(path)
76
        //     }
77
        // });
78
    })
79
  
80
    function load_sbAdmin2Js(transition){
81
        var toID = transition.$id;
0 ignored issues
show
Unused Code introduced by
The variable toID seems to be never used. Consider removing it.
Loading history...
82
        var toName = transition.to().name;
83
        var childName = toName.split(".");
84
85
        // initial the menu after the ng-include finished
86
        $('#side-menu').metisMenu('dispose');
87
        $('ul.nav a[class="active"]').removeClass("active")
88
        $('#side-menu').metisMenu();
89
90
        $(window).bind("load resize", function() {
91
            var topOffset = 50;
92
            var width = (this.window.innerWidth > 0) ? this.window.innerWidth : this.screen.width;
93
            if (width < 768) {
94
                $('div.navbar-collapse').addClass('collapse');
95
                topOffset = 100; // 2-row-menu
96
            } else {
97
                $('div.navbar-collapse').removeClass('collapse');
98
            }
99
100
            var height = ((this.window.innerHeight > 0) ? this.window.innerHeight : this.screen.height) - 1;
101
            height = height - topOffset;
102
            if (height < 1) height = 1;
103
            if (height > topOffset) {
104
                $("#page-wrapper").css("min-height", (height) + "px");
105
            }
106
        });
107
108
        // keithpoon, 20180221, remove all class for single page application
109
        var element = $('ul.nav a[ui-sref]').filter(function() {
110
            var uiSref = $(this).attr('ui-sref')
111
112
            if(toName == uiSref)
113
                return true;
114
            if(childName.length>0)
115
            {
116
                if(uiSref.indexOf('.') == 0)
117
                    return uiSref.substring(1) == childName[childName.length-1];
118
            }
119
120
            return false;
121
        }).addClass('active').parent();
122
123
        while (true) {
124
            if (element.is('li')) {
125
                element = element.parent().addClass('in').parent();
126
            } else {
127
                break;
128
            }
129
        }
130
    }
131
132
});